package com.leaf.spring.y202003.day09.redis;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

/**
 * redis 集群操作
 *@Title:  
 *@Description:  
 *@Author: leaf  
 *@Since:2020年3月12日  
 *@Version:1.1.0
 */
public class TestClusterRedis {
	
	@Test
	public void test() throws IOException {
		
		Set<HostAndPort> jedisClusterNode = new HashSet<>();
		
		jedisClusterNode.add(new HostAndPort("192.168.89.95", 7001));
		jedisClusterNode.add(new HostAndPort("192.168.89.95", 7002));
		jedisClusterNode.add(new HostAndPort("192.168.89.95", 7003));
		jedisClusterNode.add(new HostAndPort("192.168.89.95", 7004));
		jedisClusterNode.add(new HostAndPort("192.168.89.95", 7005));
		jedisClusterNode.add(new HostAndPort("192.168.89.95", 7006));
		
		JedisPoolConfig jpc = new JedisPoolConfig();
		
		jpc.setMaxTotal(100);
		jpc.setMaxIdle(20);
		jpc.setMaxWaitMillis(-1);
		jpc.setTestOnBorrow(true);
		
		JedisCluster jc = new JedisCluster(jedisClusterNode, 6000, 1000, jpc);
		
		System.out.println(jc.set("age", "22"));
		System.out.println(jc.lpush("users", "zhangsan", "lisi", "wangwu"));
		
		System.out.println(jc.get("age"));
		System.out.println(jc.rpush("user", "zhangsan"));
		
		jc.close();
		
	}

}
